# -*- coding:utf-8
"""
作者: Jia
日期: 2022年04月17日
描述: https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/
"""
from typing import List


class Solution:
    def averageI(self, salary: List[int]) -> float:
        max_val = max(salary)
        min_val = min(salary)
        sum_val = sum(salary)
        ans = (sum_val - max_val - min_val) / (len(salary) - 2)
        return ans

    def average(self, salary: List[int]) -> float:
        max_val = 0
        min_val = 10e7
        sum_val = 0
        for num in salary:
            max_val = max(max_val, num)
            min_val = min(min_val, num)
            sum_val += num
        ans = (sum_val - max_val - min_val) / (len(salary) - 2)
        return ans


salary = [4000, 3000, 1000, 2000]
s = Solution()
s.average(salary)
